#ifndef __NUMRULE_H
#define __NUMRULE_H

#include <string>
#include <set>
#include "number.h"

using namespace std;

/** A class describing a number parsing rule in a language state machine.
 * Used by LanguageParser
 */
class NumRule {
  private:
    /** Input state. 
     * For reference only, also used if new_state is undefined. */
    string state;
    /** Input literal. 
     * For reference only, also used in error messages. */
    string literal;

    // for action...
    /** Semantics.
     * Defines what this rule should do with the current value of a number. 
     */
    string semantics;
    /** New state.
     * Defines what the new state of the parser should be after having applied
     * this rule.
     */
    string new_state;

    // for checks...
    /** A set of flags. 
     * Defines what flags should be added / removed / checked against when this
     * rule is being applied.
     */
    set<string> flags;

  public:
    /** Create NumRule from key-value pair.
     *
     * @param key is: "STATE,literal"
     * @param value is "semantics:NEW_STATE:flags"
     */
    NumRule(string key, string value);

    /** Apply the rule to a Number.
     * Modifies the subtotal, current value and flags of the number
     *
     * @param n the Number to apply the rule on.
     * @return the new state.
     */
    string apply(Number &n) const;
};

#endif
